import handleNum from './NumStatus'
import handleArr from './ArrStatus'

const defaultState = {
  ...handleNum.state,
  ...handleArr.state
}

const handles = [
  handleNum,
  handleArr
]

let reducer = (state = defaultState , action:{type:string, num:number}) => {
  // console.log(action)
  let newState = JSON.parse(JSON.stringify(state))

  // switch(action.type){
  //   case handleNum.add:
  //     handleNum.actions[handleNum.add](newState,action)
  //     break;
  //   case handleNum.minus:
  //     handleNum.actions[handleNum.minus](newState,action)
  //     break;
  //   case handleArr.sArrPush:
  //     handleArr.actions[handleArr.sArrPush](newState,action)
  //     break;
  //   default:
  //     break;
  // }
  //for优化方案
  handles.forEach((ele)=>{
    for (let key in ele.actionNames){
      if(action.type===ele.actionNames[key]){
        ele.actions[ele.actionNames[key]](newState,action)
        break;
      }
    }
  })

  return newState
}

export default reducer